#!/bin/bash

expect <<EOF
 set timeout 300
  spawn docker exec -it  elasticsearch  ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.14.0/elasticsearch-analysis-ik-7.14.0.zip
  expect "y/N"
  send "y\r"
EOF

cd /data/docker/
docker-compose -f docker-compose-elasticsearch.yml restart

filecopy elasticsearch/config/certs/
filecopy elasticsearch/config/elasticsearch.keystore
filecopy elasticsearch/plugins/


ssh ${IP2}  "chmod 777 -R /data/docker/elasticsearch;docker-compose -f  /data/docker/docker-compose-elasticsearch.yml restart"
ssh ${IP3}  "chmod 777 -R /data/docker/elasticsearch;docker-compose -f  /data/docker/docker-compose-elasticsearch.yml restart"

sleep 0.5m

expect <<EOF
  set timeout 10
  spawn docker exec -it elasticsearch ./bin/elasticsearch-setup-passwords interactive
  expect "y/N"
  send "y\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect "*password*"
  send "elasticsearch\r"
  expect eof
EOF

rm -rf /data/docker/elasticsearch/otherinstall.sh
